﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace CodeCity.AutomationMachine.DomainModels
{
    public class Human : ModelBase
    {
        private ReaderWriterLockSlim temperatureLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim temperatureOutOfNormalSecondsLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim isPatientLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim growSpeedLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim remainLifeLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim isDeadedLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim birthTimeLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim bornLocker = new ReaderWriterLockSlim();
        private ReaderWriterLockSlim nameLocker = new ReaderWriterLockSlim();
        /// <summary>
        /// 体温
        /// </summary>
        public static float InitilizeTemperature { get; set; } = 36;
        public static double MaxNormalTemperature = 46;
        public static double MinNormalTemperature = 20;
        public static int MaxAgeDay = 20;

        private double temperature;
        private double temperatureOutOfNormalSeconds;
        private bool isPatient;
        private double growSpeed;
        private double remainLife;
        private bool isDeaded;
        private DateTime birthTime;
        private bool isBorn;
        private string name;
        public DateTime BirthTime
        {
            get
            {
                return WithReadLock<Human, DateTime>(birthTimeLocker, x => x.birthTime);
            }
            set
            {
                WithWriteLock<Human>(birthTimeLocker, x => x.birthTime = value);
            }
        }
        public bool IsBorn
        {
            get
            {
                return WithReadLock<Human, bool>(bornLocker, x => x.isBorn);
            }
            set
            {
                WithWriteLock<Human>(bornLocker, x => x.isBorn = value);
            }
        }
        public string Name
        {
            get
            {
                return WithReadLock<Human, string>(nameLocker, x => x.name);
            }
            set
            {
                WithWriteLock<Human>(nameLocker, x => x.name = value);
            }
        }

        public double Temperature
        {
            get
            {
                return WithReadLock<Human, double>(temperatureLocker, x => x.temperature);
            }
            set
            {
                WithWriteLock<Human>(temperatureLocker, x => x.temperature = value);
            }
        }

        public double TemperatureOutOfNormalSeconds
        {
            get
            {
                return WithReadLock<Human, double>(temperatureOutOfNormalSecondsLocker, x => x.temperatureOutOfNormalSeconds);
            }
            set
            {
                WithWriteLock<Human>(temperatureOutOfNormalSecondsLocker, x => x.temperatureOutOfNormalSeconds = value);
            }
        }

        public bool IsPatient
        {
            get
            {
                return WithReadLock<Human, bool>(isPatientLocker, x => x.isPatient);
            }
            set
            {
                WithWriteLock<Human>(isPatientLocker, x => x.isPatient = value);
            }
        }
        public double GrowSpeed
        {
            get
            {
                return WithReadLock<Human, double>(growSpeedLocker, x => x.growSpeed);
            }
            set
            {
                WithWriteLock<Human>(growSpeedLocker, x => x.growSpeed = value);
            }
        }

        public bool IsDeaded
        {
            get
            {
                return WithReadLock<Human, bool>(isDeadedLocker, x => x.isDeaded);
            }
            set
            {
                WithWriteLock<Human>(isDeadedLocker, x => x.isDeaded = value);
            }
        }
        public double RemainLife
        {
            get
            {
                return WithReadLock<Human, double>(remainLifeLocker, x => x.remainLife);
            }
            set
            {
                WithWriteLock<Human>(remainLifeLocker, x => x.remainLife = value);
            }
        }
    }
}
